<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>ComputerERP主页</title>
  <link rel="stylesheet" href="/static/js/layui/css/layui.css">
  <script type="text/javascript" src="/static/js/jquery/jquery-3.5.1.min.js"></script>
  <script type="text/javascript" src="/static/js/layui/layui.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <!--    上方导航栏-->
  <div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black"><a style="color: #E9E7E7" class="" th:href="@{/admin/main}">ComputerERP</a></div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <!--        <ul class="layui-nav layui-layout-left">-->
    <!--            &lt;!&ndash; 移动端显示 &ndash;&gt;-->
    <!--            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">-->
    <!--                <i class="layui-icon layui-icon-spread-left"></i>-->
    <!--            </li>-->

    <!--            <li class="layui-nav-item layui-hide-xs"><a href="">nav 1</a></li>-->
    <!--            <li class="layui-nav-item layui-hide-xs"><a href="">nav 2</a></li>-->
    <!--            <li class="layui-nav-item layui-hide-xs"><a href="">nav 3</a></li>-->
    <!--            <li class="layui-nav-item">-->
    <!--                <a href="javascript:;">nav groups</a>-->
    <!--                <dl class="layui-nav-child">-->
    <!--                    <dd><a href="">menu 11</a></dd>-->
    <!--                    <dd><a href="">menu 22</a></dd>-->
    <!--                    <dd><a href="">menu 33</a></dd>-->
    <!--                </dl>-->
    <!--            </li>-->
    <!--        </ul>-->
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide layui-show-md-inline-block">
<!--        <a href="javascript:;">-->
<!--&lt;!&ndash;          <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg" class="layui-nav-img">&ndash;&gt;-->
<!--          tester-->
<!--        </a>-->
<!--        <dl class="layui-nav-child">-->
<!--          <dd><a th:href="@{/main/selfinformation}">个人信息</a></dd>-->
<!--          <dd><a href="">退出登录</a></dd>-->
<!--        </dl>-->
      </li>
      <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
        <a href="javascript:;">
          <i class="layui-icon layui-icon-more-vertical"></i>
        </a>
      </li>
    </ul>
  </div>
  <!--左侧导航栏-->
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree" lay-filter="test">
        <li class="layui-nav-item">
          <a class="" href="javascript:;">进货管理</a>
          <dl class="layui-nav-child">
            <dd><a th:href="@{/main/purchase/pmanagement}">进货入库</a></dd>
            <dd><a th:href="@{/main/purchase/omanagement}">退货出库</a></dd>
            <dd><a th:href="@{/main/purchase/pmanagementorder}">进货单查询</a></dd>
            <dd><a th:href="@{/main/purchase/omanagementorder}">退货单查询</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item ">
          <a href="javascript:;">销售管理</a>
          <dl class="layui-nav-child">
            <dd><a th:href="@{/main/sales/salesdelivery}">销售出库</a></dd>
            <dd><a th:href="@{/main/sales/omanagement}">客户退货</a></dd>
            <dd><a th:href="@{/main/sales/salesorder}">销售单查询</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item ">
          <a class="" href="javascript:;">库存管理</a>
          <dl class="layui-nav-child">
            <dd><a th:href="@{/main/warehouse/damage}">商品报损/报溢</a></dd>
            <dd><a th:href="@{/main/warehouse/alarm}">库存报警</a></dd>
            <dd><a th:href="@{/main/warehouse/brimordamage}">报损报溢查询</a></dd>
            <dd><a th:href="@{/main/warehouse/querywarehouse}">当前库存查询</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a class="" th:href="@{/main/report/report}">统计报表</a>
        <li class="layui-nav-item ">
          <a class="" th:href="@{/main/manage/manage}">系统设置</a>
        </li>
      </ul>
    </div>
  </div>
  <!--主体区域-->
  <!--    <div class="layui-body">-->
  <!--        &lt;!&ndash; 内容主体区域 &ndash;&gt;-->
  <!--&lt;!&ndash;        <div style="padding: 15px;">内容主体区域。记得修改 layui.css 和 js 的路径</div>&ndash;&gt;-->
  <!--    </div>-->



  <div class="layui-tab layui-tab-brief">
      <div class="layui-body layui-tab-content" style="background-image: url(/static/images/bg2.jpg); height: 930px; background-repeat: no-repeat; ">
          <div class="layui-tab-item layui-show">
              <div class="layui-main">
<!--          <div id="LAY_layedit_code">-->
<!--            <div style="margin:0 auto; max-width: 1140px;">-->
<!--              &lt;!&ndash;                            这里写主体内容&ndash;&gt;-->
<!--            </div>-->
<!--          </div>-->
                  <div class="layui-tab">
                      <ul class="layui-tab-title">
                          <li class="layui-this">用户管理</li>
                          <li>客户管理</li>
                          <li>商品管理</li>
                          <li>供货商管理</li>
                      </ul>
                      <div class="layui-tab-content" >
                          <div class="layui-tab-item layui-show"><!--用户管理-->
                            <div class="layui-col-md10 layui-col-md-offset1">
                              <div style="margin:auto; max-width: 1140px;">

                                <form class="layui-form" action="">
                                  <div class="layui-form-item" style="text-align: center">
                                    <div class="layui-inline">
                                      <label class="layui-form-label" style="width: 50px">员工ID</label>
                                      <div class="layui-input-inline " id="userId" style="overflow: visible; width: 180px">
                                        <select name="modules" class="userId" lay-verify="required" lay-search="">
                                          <option value="">直接选择或搜索选择</option>
                                          <option value="1">1</option>
                                          <option value="2">2</option>
                                        </select>
                                      </div>
                                      <label class="layui-form-label" style="width: 50px">员工名</label>
                                      <div class="layui-input-inline " id="userName" style="overflow: visible; width: 180px">
                                        <select name="modules" class="userName" lay-verify="required" lay-search="">
                                          <option value="">直接选择或搜索选择</option>
                                          <option value="1">张三</option>
                                          <option value="2">李四</option>
                                        </select>
                                      </div>
                                      <div class="layui-inline ">
                                        <div class="layui-btn-container">
                                          <button type="button" id="selectbtn1" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" style="width:50px;height: 38px;">查找</button>
                                          <button type="button" id="inbtn1" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" style="width:50px;height: 38px;">添加</button>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                </form>

                                <div class="layui-form">
                                  <table class="layui-table" id="userTable">
                                    <thead>
                                    <tr>
                                      <th>员工id</th>
                                      <th>员工姓名</th>
                                      <th>用户名</th>
                                      <th>部门</th>
                                      <th>入职时间</th>
                                      <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                      <td>123456789</td>
                                      <td>张三</td>
                                      <td>zhangsan</td>
                                      <td>采购部门</td>
                                      <td>2022-5-5</td>
                                      <td>
                                        <div class="layui-btn-container">
                                          <button type="button" id="delbtn1" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm">删除</button>
                                        </div>
                                      </td>
                                    </tr>
                                    </tbody>
                                  </table>
                                </div>
                              </div>
                            </div>
                          </div>
                          <div class="layui-tab-item"><!--客户管理-->
                            <div class="layui-col-md8 layui-col-md-offset2">
                              <div style="margin:auto; max-width: 1140px;">

                                <form class="layui-form" action="">
                                  <div class="layui-form-item" style="text-align: center">
                                    <div class="layui-inline">
                                      <label class="layui-form-label" style="width: 50px">客户ID</label>
                                      <div class="layui-input-inline " id="customerId" style="overflow: visible; width: 180px">
                                        <select name="modules" class="customerId" lay-verify="required" lay-search="">
                                          <option value="">直接选择或搜索选择</option>
                                          <option value="1">1</option>
                                          <option value="2">2</option>
                                        </select>
                                      </div>
                                      <label class="layui-form-label" style="width: 50px">客户名</label>
                                      <div class="layui-input-inline " id="customerName" style="overflow: visible; width: 180px">
                                        <select name="modules" class="customerName" lay-verify="required" lay-search="">
                                          <option value="">直接选择或搜索选择</option>
                                          <option value="1">张三</option>
                                          <option value="2">李四</option>
                                        </select>
                                      </div>
                                      <div class="layui-inline ">
                                        <div class="layui-btn-container">
                                          <button type="button" id="selectbtn2" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" style="width:50px;height: 38px;">查找</button>
                                          <button type="button" id="inbtn2" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" style="width:50px;height: 38px;">添加</button>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                </form>

                                <div class="layui-form">
                                  <table class="layui-table" id="customerTable">
                                    <thead>
                                    <tr>
                                      <th>客户id</th>
                                      <th>客户姓名</th>
                                      <th>客户联系方式</th>
                                      <th style="width: 250px">客户地址</th>
                                      <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                      <td>123456789</td>
                                      <td>张三</td>
                                      <td>张三的地址们</td>
                                      <td>
                                        <div class="layui-btn-container">
                                          <button type="button" id="delbtn2" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm">删除</button>
                                        </div>
                                      </td>
                                    </tr>
                                    </tbody>
                                  </table>
                                </div>
                              </div>
                            </div>
                          </div>
                          <div class="layui-tab-item"><!--商品管理-->
                            <div class="layui-col-md8 layui-col-md-offset2">
                              <div style="margin:auto; max-width: 1140px;">

                                <form class="layui-form" action="">
                                  <div class="layui-form-item" style="text-align: center">
                                    <div class="layui-inline">
                                      <label class="layui-form-label" style="width: 50px">零件ID</label>
                                      <div class="layui-input-inline " id="lingjianId" style="overflow: visible; width: 180px">
                                        <select name="modules" class="lingjianId" lay-verify="required" lay-search="">
                                          <option value="">直接选择或搜索选择</option>
                                          <option value="1">1</option>
                                          <option value="2">2</option>
                                        </select>
                                      </div>
                                      <label class="layui-form-label" style="width: 50px">零件名</label>
                                      <div class="layui-input-inline " id="lingjianName" style="overflow: visible; width: 180px">
                                        <select name="modules" class="lingjianName" lay-verify="required" lay-search="">
                                          <option value="">直接选择或搜索选择</option>
                                          <option value="1">张三</option>
                                          <option value="2">李四</option>
                                        </select>
                                      </div>
                                      <div class="layui-inline ">
                                        <div class="layui-btn-container">
                                          <button type="button" id="selectbtn3" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" style="width:50px;height: 38px;">查找</button>
                                          <button type="button" id="inbtn3" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" style="width:50px;height: 38px;">添加</button>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                </form>

                                <div class="layui-form">
                                  <table class="layui-table" id="lingjianTable">
                                    <thead>
                                    <tr>
                                      <th>商品id</th>
                                      <th>商品名</th>
                                      <th>商品价格</th>
                                      <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                      <td>123456789</td>
                                      <td>张三</td>
                                      <td>28.95</td>
                                      <td>
                                        <div class="layui-btn-container">
                                          <button type="button" id="delbtn3" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm">删除</button>
                                        </div>
                                      </td>
                                    </tr>
                                    </tbody>
                                  </table>
                                </div>
                              </div>
                            </div>
                          </div>
                          <div class="layui-tab-item"><!--供货商管理-->
                            <div class="layui-col-md8 layui-col-md-offset2">
                              <div style="margin:auto; max-width: 1140px;">

                                <form class="layui-form" action="">
                                  <div class="layui-form-item" style="text-align: center">
                                    <div class="layui-inline">
                                      <label class="layui-form-label" style="width: 80px">供货商ID</label>
                                      <div class="layui-input-inline " id="merchantId" style="overflow: visible; width: 180px">
                                        <select name="modules" class="merchantId" lay-verify="required" lay-search="">
                                          <option value="">直接选择或搜索选择</option>
                                          <option value="1">1</option>
                                          <option value="2">2</option>
                                        </select>
                                      </div>
                                      <label class="layui-form-label" style="width: 80px">供货商名</label>
                                      <div class="layui-input-inline " id="merchantName" style="overflow: visible; width: 180px">
                                        <select name="modules" class="merchantName" lay-verify="required" lay-search="">
                                          <option value="">直接选择或搜索选择</option>
                                          <option value="1">张三</option>
                                          <option value="2">李四</option>
                                        </select>
                                      </div>
                                      <div class="layui-inline ">
                                        <div class="layui-btn-container">
                                          <button type="button" id="selectbtn4" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" style="width:50px;height: 38px;">查找</button>
                                          <button type="button" id="inbtn4" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" style="width:50px;height: 38px;">添加</button>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                </form>

                                <div class="layui-form">
                                  <table class="layui-table" id="merchantTable">
                                    <thead>
                                    <tr>
                                      <th>供货商id</th>
                                      <th>供货商名</th>
                                      <th>供货商地址</th>
                                      <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                      <td>123456789</td>
                                      <td>张三</td>
                                      <td>供货商地址</td>
                                      <td>
                                        <div class="layui-btn-container">
                                          <button type="button" id="delbtn" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm">删除</button>
                                        </div>
                                      </td>
                                    </tr>
                                    </tbody>
                                  </table>
                                </div>
                              </div>
                            </div>
                          </div>
                          <div class="layui-tab-item"><!--菜单管理-->


                          </div>
                      </div>
                  </div>

             </div>
          </div>
      </div>
  </div>
</div>

<script>
  //JS
  layui.use(['element', 'layer', 'util'], function(){
    var element = layui.element
            ,layer = layui.layer
            ,util = layui.util
            ,$ = layui.$;

    //头部事件
    util.event('lay-header-event', {
      //左侧菜单事件
      menuLeft: function(othis){
        layer.msg('展开左侧菜单的操作', {icon: 0});
      }
      ,menuRight: function(){
        layer.open({
          type: 1
          ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
          ,area: ['260px', '100%']
          ,offset: 'rt' //右上角
          ,anim: 5
          ,shadeClose: true
        });
      }
    });
  });
  $(function () {
    //请求数据
    requestdata();
    function requestdata(){
      $.ajax({
        url:"/main/manage/select/manage",
        type:"post",
        dataType:"json",
        success:function (data){
          // console.log(data);
          $("#userId").empty();
          $("#userName").empty();
          let select11 = '<select name="modules" className="userId" lay-verify="required" lay-search="">';
          select11 += '<option value="99">直接选择或搜索</option>';
          let select12 = '<select name="modules" className="userName" lay-verify="required" lay-search="">';
          select12 += '<option value="99">直接选择或搜索</option>';
          for (i=0;i<data.users.length;i++){
            select11 += '<option value="'+data.users[i].id+'">'+data.users[i].id+'</option>';
            select12 += '<option value="'+data.users[i].name+'">'+data.users[i].name+'</option>';
          }
          select11 += '</select>';
          select12 += '</select>';
          $("#userId").append(select11);
          $("#userName").append(select12);

          $("#customerId").empty();
          $("#customerName").empty();
          let select21 = '<select name="modules" className="customerId" lay-verify="required" lay-search="">';
          select21 += '<option value="99">直接选择或搜索</option>';
          let select22 = '<select name="modules" className="customerName" lay-verify="required" lay-search="">';
          select22 += '<option value="99">直接选择或搜索</option>';
          for (i=0;i<data.customers.length;i++){
            select21 += '<option value="'+data.customers[i].id+'">'+data.customers[i].id+'</option>';
            select22 += '<option value="'+data.customers[i].name+'">'+data.customers[i].name+'</option>';
          }
          select21 += '</select>';
          select22 += '</select>';
          $("#customerId").append(select21);
          $("#customerName").append(select22);

          $("#merchantId").empty();
          $("#merchantName").empty();
          let select31 = '<select name="modules" className="merchantId" lay-verify="required" lay-search="">';
          select31 += '<option value="99">直接选择或搜索</option>';
          let select32 = '<select name="modules" className="merchantName" lay-verify="required" lay-search="">';
          select32 += '<option value="99">直接选择或搜索</option>';
          for (i=0;i<data.merchants.length;i++){
            select31 += '<option value="'+data.merchants[i].id+'">'+data.merchants[i].id+'</option>';
            select32 += '<option value="'+data.merchants[i].name+'">'+data.merchants[i].name+'</option>';
          }
          select31 += '</select>';
          select32 += '</select>';
          $("#merchantId").append(select31);
          $("#merchantName").append(select32);

          $("#lingjianId").empty();
          $("#lingjianName").empty();
          let select41 = '<select name="modules" className="lingjianId" lay-verify="required" lay-search="">';
          select41 += '<option value="99">直接选择或搜索</option>';
          let select42 = '<select name="modules" className="lingjianName" lay-verify="required" lay-search="">';
          select42 += '<option value="99">直接选择或搜索</option>';
          for (i=0;i<data.lingJians.length;i++){
            select41 += '<option value="'+data.lingJians[i].id+'">'+data.lingJians[i].id+'</option>';
            select42 += '<option value="'+data.lingJians[i].name+'">'+data.lingJians[i].name+'</option>';
          }
          select41 += '</select>';
          select42 += '</select>';
          $("#lingjianId").append(select41);
          $("#lingjianName").append(select42);

          //查询
          $("#selectbtn1").click();
          $("#selectbtn2").click();
          $("#selectbtn3").click();
          $("#selectbtn4").click();
          renderForm();
        }
      });
    }
    //查询user
    $("#selectbtn1").click(function (){
      var param = {"id":$("#userId").find("option:selected").text(),"name":$("#userName").find("option:selected").text()};
      // console.log(param);
      $.ajax({
        url:"/main/manage/select/users",
        data:param,
        dataType: "json",
        success:function (data){
          // console.log(data);
          $("#userTable tr:gt(0)").remove();
          if (data.result==1){
            let tr="<tr>";
            tr += '<td>'+data.user.id+'</td>';
            tr += '<td>'+data.user.name+'</td>';
            tr += '<td>'+data.user.username+'</td>';
            if (data.user.departmentId==1){
              tr += '<td>'+"采购部门"+'</td>';
            }else if (data.user.departmentId==2){
              tr += '<td>'+"销售部门"+'</td>';
            }
            if (data.user.entryTime==""){
              tr += '<td>'+""+'</td>';
            }else{
              tr += '<td>'+data.user.entryTime+'</td>';
            }
            tr += '<td><button type="button" id="delbtn1" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.user.id+'>删除</button><td></tr>';
            $('#userTable').append(tr);
          }else {
            for (i=0;i<data.users.length;i++){
              let tr="<tr>";
              tr += '<td>'+data.users[i].id+'</td>';
              tr += '<td>'+data.users[i].name+'</td>';
              tr += '<td>'+data.users[i].username+'</td>';
              if (data.users[i].departmentId==1){
                tr += '<td>'+"采购部门"+'</td>';
              }else if (data.users[i].departmentId==2){
                tr += '<td>'+"销售部门"+'</td>';
              }
              if (data.users[i].entryTime==null){
                tr += '<td>'+""+'</td>';
              }else{
                tr += '<td>'+data.users[i].entryTime+'</td>';
              }
              tr += '<td><button type="button" id="delbtn1" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.users[i].id+'>删除</button></td></tr>'
              $('#userTable').append(tr);
            }
          }

        }
      });
    });
    //删除user
    $(document).on("click","#delbtn1",function(){
      var param = {"id":$(this).data("id")};
      // console.log(param);
      $.ajax({
        url:"/main/manage/delete/users",
        data: param,
        dataType:"json",
        success:function (data){
          if (data==1){
            layer.msg("删除成功！");
            $("#selectbtn1").click();
          }else {
            layer.msg("遇到未知错误！");
          }
        }
      });
    });
    //添加user
    $("#inbtn1").click(function (){
       layer.open({
         type: 2,
         title: '添加用户信息',
         shadeClose: true,
         shade: false,
         maxmin: false, //开启最大化最小化按钮
         area: ['320px', '350px'],
         content: '/main/manage/toinsertuser',
         end: function (){
           $("#selectbtn1").click();
         }
       });
    });
    //查询customer
    $("#selectbtn2").click(function (){
      var param = {"id":$("#customerId").find("option:selected").text(),"name":$("#customerName").find("option:selected").text()};
      // console.log(param);
      $.ajax({
        url:"/main/manage/select/customers",
        data:param,
        dataType: "json",
        success:function (data){
          // console.log(data);
          $("#customerTable tr:gt(0)").remove();
          if (data.result==1){
            let tr="<tr>";
            tr += '<td>'+data.customer.id+'</td>';
            tr += '<td>'+data.customer.name+'</td>';
            tr += '<td>'+data.customer.phone+'</td>';
            tr += '<td>';
            for (j=0;j<data.customerAddresses.length;j++){
              if (data.customerAddresses[j].customerId==data.customer.id){
                tr += '<div><span>'+data.customerAddresses[j].address+'</span>';
              }
            }
            tr += '</td>';
            tr += '<td><button type="button" id="delbtn2" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.customer.id+'>删除</button><td></tr>';
            $('#customerTable').append(tr);
          }else {
            for (i=0;i<data.customers.length;i++){
              let tr="<tr>";
              tr += '<td>'+data.customers[i].id+'</td>';
              tr += '<td>'+data.customers[i].name+'</td>';
              tr += '<td>'+data.customers[i].phone+'</td>';
              tr += '<td>';
                for (j=0;j<data.customerAddresses.length;j++){
                  if (data.customerAddresses[j].customerId==data.customers[i].id){
                    tr += '<div><span>'+data.customerAddresses[j].address+'</span>';
                    // tr += '<span><button type="button" id="delbtn21" style="position: relative;margin: auto auto 5px auto" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.customerAddresses[j].id+'>删除</button></span></div>';
                  }
                }
              tr += '</td>';
              tr += '<td><button type="button" id="delbtn2" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.customers[i].id+'>删除</button></td></tr>'
              $('#customerTable').append(tr);
            }
          }

        }
      });
    });
    //删除customer
    $(document).on("click","#delbtn2",function(){
      var param = {"id":$(this).data("id")};
      console.log(param);
      $.ajax({
        url:"/main/manage/delete/customers",
        data: param,
        dataType:"json",
        success:function (data){
          if (data==1){
            layer.msg("删除成功！");
            $("#selectbtn2").click();
          }else {
            layer.msg("遇到未知错误！");
          }
        }
      });
    });
    //添加customer
    $("#inbtn2").click(function (){
      layer.open({
        type: 2,
        title: '添加客户信息',
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['350px', '400px'],
        content: '/main/manage/toinsertcustomer',
        end: function (){
          $("#selectbtn2").click();
        }
      });
    });
    //查询lingjian
    $("#selectbtn3").click(function (){
      var param = {"id":$("#lingjianId").find("option:selected").text(),"name":$("#lingjianName").find("option:selected").text()};
      // console.log(param);
      $.ajax({
        url:"/main/manage/select/lingjains",
        data:param,
        dataType: "json",
        success:function (data){
          // console.log(data);
          $("#lingjianTable tr:gt(0)").remove();
          if (data.result==1){
            let tr="<tr>";
            tr += '<td>'+data.lingJian.id+'</td>';
            tr += '<td>'+data.lingJian.name+'</td>';
            tr += '<td>'+data.lingJian.price+'</td>';
            tr += '<td><button type="button" id="delbtn3" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.lingJian.id+'>删除</button></td></tr>';
            $('#lingjianTable').append(tr);
          }else {
            for (i=0;i<data.lingJians.length;i++){
              let tr="<tr>";
              tr += '<td>'+data.lingJians[i].id+'</td>';
              tr += '<td>'+data.lingJians[i].name+'</td>';
              tr += '<td>'+data.lingJians[i].price+'</td>';
              tr += '<td><button type="button" id="delbtn3" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.lingJians[i].id+'>删除</button></td></tr>'
              $('#lingjianTable').append(tr);
            }
          }
        }
      });
    });
    //删除lingjian
    $(document).on("click","#delbtn3",function(){
      var param = {"id":$(this).data("id")};
      console.log(param);
      $.ajax({
        url:"/main/manage/delete/lingjians",
        data: param,
        dataType:"json",
        success:function (data){
          if (data==1){
            layer.msg("删除成功！");
            $("#selectbtn3").click();
          }else {
            layer.msg("遇到未知错误！");
          }
        }
      });
    });
    //添加lingjian
    $("#inbtn3").click(function (){
      layer.open({
        type: 2,
        title: '添加商品信息',
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['350px', '240px'],
        content: '/main/manage/toinsertlingjian',
        end: function (){
          $("#selectbtn3").click();
        }
      });
    });
    //查询merchant
    $("#selectbtn4").click(function (){
      var param = {"id":$("#merchantId").find("option:selected").text(),"name":$("#merchantName").find("option:selected").text()};
      // console.log(param);
      $.ajax({
        url:"/main/manage/select/merchants",
        data:param,
        dataType: "json",
        success:function (data){
          // console.log(data);
          $("#merchantTable tr:gt(0)").remove();
          if (data.result==1){
            let tr="<tr>";
            tr += '<td>'+data.merchant.id+'</td>';
            tr += '<td>'+data.merchant.name+'</td>';
            tr += '<td>'+data.merchant.address+'</td>';
            tr += '<td><button type="button" id="delbtn4" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.merchant.id+'>删除</button></td></tr>';
            $('#merchantTable').append(tr);
          }else {
            for (i=0;i<data.merchants.length;i++){
              let tr="<tr>";
              tr += '<td>'+data.merchants[i].id+'</td>';
              tr += '<td>'+data.merchants[i].name+'</td>';
              tr += '<td>'+data.merchants[i].address+'</td>';
              tr += '<td><button type="button" id="delbtn4" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" data-id='+data.merchants[i].id+'>删除</button></td></tr>'
              $('#merchantTable').append(tr);
            }
          }
        }
      });
    });
    //删除merchant
    $(document).on("click","#delbtn4",function(){
      var param = {"id":$(this).data("id")};
      console.log(param);
      $.ajax({
        url:"/main/manage/delete/merchants",
        data: param,
        dataType:"json",
        success:function (data){
          if (data==1){
            layer.msg("删除成功！");
            $("#selectbtn4").click();
          }else {
            layer.msg("遇到未知错误！");
          }
        }
      });
    });
    //添加merchant
    $("#inbtn4").click(function (){
      layer.open({
        type: 2,
        title: '添加供货商信息',
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['350px', '400px'],
        content: '/main/manage/toinsertmerchant',
        end:function (){
          $("#selectbtn4").click();
        }
      });
    });
    //渲染
    function renderForm() {
      layui.use('form', function () {
        var form = layui.form;
        form.render();
      });
      return;
    }
  });
</script>
</body>
</html>